package liuqy.service.impl;

import java.util.List;

import liuqy.mapper.ItemMapper;
import liuqy.mapper.ItemsMapperCustom;
import liuqy.po.Item;
import liuqy.po.ItemCustom;
import liuqy.po.ItemQueryVo;
import liuqy.service.ItemService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 根据入参查询对应的商品列表
 * 查询商品列表
 * @author user
 *
 */
public class ItemServiceImpl implements ItemService {
	/**
	 * spring 通过注入的方式可以直接调用ItemsMapperCustom
	 */
	@Autowired
	private ItemsMapperCustom itemsMapperCustom; 
	
	@Autowired
	private ItemMapper itemMapper;
	public List<ItemCustom> findItemsList(ItemQueryVo itemQueryVo)
			throws Exception {
		return itemsMapperCustom.findItemsList(itemQueryVo); 
	}
	
	@Override
	public ItemCustom selectItemById(Integer id) throws Exception {
		Item item = itemMapper.selectByPrimaryKey(id);
		ItemCustom itemCustom = new ItemCustom();
		//将A的数据根据属性拷贝到B表
		BeanUtils.copyProperties(item, itemCustom);
		return itemCustom;
		
	}
	
	@Override
	public void updateItem(Integer id,ItemCustom itemCustom) throws Exception {

		//业务校验  判断Id是否为空
		if(id == null){
			throw new Exception("商品编号不允许为空！");
		}
		
		itemCustom.setId(id);
		itemMapper.updateByPrimaryKey(itemCustom);
	}

	@Override
	public void deleteItem(Integer id) throws Exception {
		if(id == null){
			throw new Exception("商品编号不允许为空！");
		}
		itemMapper.deleteByPrimaryKey(id);
		
	}
	
}
